/*
 *  Copyright (c) 2013 Hai Bison
 *
 *  See the file LICENSE at the root directory of this project for copying
 *  permission.
 */

package com.haibison.android.hutieu.utils;

import android.annotation.TargetApi;
import android.os.AsyncTask;
import android.os.Build;

/**
 * Helper class for {@link AsyncTask} in API 11+.
 * 
 * @author Hai Bison
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class AsyncTaskCompat_v11 {

    /**
     * This is singleton class.
     */
    private AsyncTaskCompat_v11() {
    }// AsyncTaskCompat_v11()

    /**
     * Wrapper for {@link AsyncTask}'s executors.
     * 
     * @author Hai Bison
     */
    public static enum Executor {
        /**
         * Wrapper for {@link AsyncTask#SERIAL_EXECUTOR}.
         */
        SERIAL(AsyncTask.SERIAL_EXECUTOR),
        /**
         * Wrapper for {@link AsyncTask#THREAD_POOL_EXECUTOR}.
         */
        THREAD_POOL(AsyncTask.THREAD_POOL_EXECUTOR);

        /**
         * The target executor.
         */
        public final java.util.concurrent.Executor executor;

        /**
         * Creates new instance.
         * 
         * @param executor
         *            the target executor.
         */
        private Executor(java.util.concurrent.Executor executor) {
            this.executor = executor;
        }// Executor()

    }// Executor

    /**
     * Wrapper for {@link AsyncTask#executeOnExecutor(Executor, Object...)}.
     * 
     * @param task
     *            the async task.
     * @param exec
     *            see original method.
     * @param params
     *            see original method.
     * @return see original method.
     */
    public static <Params, Progress, Result> AsyncTask<Params, Progress, Result> executeOnExecutor(
            AsyncTask<Params, Progress, Result> task, Executor exec,
            Params... params) {
        return task.executeOnExecutor(exec.executor, params);
    }// executeOnExecutor()

}
